﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;

namespace HRM.UI.HRManagerUI.EmpSalary
{
    public partial class AddSalary : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void SaveEmpSalary(object sender, EventArgs e)
        {
            try
            {
                Employee employee = new Employee();
                Code code = new Code();
                code.CodeName = txtEmployeeCodepm.Value;
                employee.EmpCode = code;
                SalaryManager salaryManager = new SalaryManager();
                Salary aSalary = new Salary();
                aSalary.Employee = employee;
                aSalary.Basic = Convert.ToDecimal(txtBasicSalary.Value);
                aSalary.Medical = Convert.ToDecimal(txtMedical.Value);
                aSalary.Residence = Convert.ToDecimal(txtResidence.Value);
                aSalary.Transport = Convert.ToDecimal(txtTransport.Value);
                aSalary.PF = Convert.ToDecimal(txtProfidentFund.Value);
                aSalary.Mobile = Convert.ToDecimal(txtMobile.Value);
                aSalary.Others = Convert.ToDecimal(txtOthers.Value);
                aSalary.Gross = Convert.ToDecimal(txtGrossSalary.Value);
                string msg = salaryManager.SaveEmployeeSalary(aSalary);
                if (msg.Contains("Successfully"))
                {
                    msgLevel.ForeColor = Color.Green;
                    msgLevel.Text = "Salary Structure Created Successfully for Employee " + "-" + code.CodeName;
                    PopulateSalary(code);
                }
                else
                {
                    msgLevel.ForeColor = Color.Red;
                    msgLevel.Text = msg;
                    PopulateSalary(code);
                }


            }
            catch (Exception ex)
            {

                msgLevel.ForeColor = Color.Red;
                msgLevel.Text = ex.Message;
            }


        }
        protected void PopulateSalary(Code code)
        {
            SalaryManager salaryManager = new SalaryManager();
            Salary salary = new Salary();
            salary = salaryManager.GetEmployeeSalaryStructure(code);
            List<Salary> salarylist = new List<Salary>();
            salarylist.Add(salary);
            singleSalaryGdv.DataSource = salarylist;
            singleSalaryGdv.DataBind();

        }
    }
}